package com.kkb.billmngapi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.kkb.billmngapi.dao.BillDao;
import com.kkb.springcloudbill.entity.Bill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BillService {
    @Autowired
    public BillDao billDao;

    public PageInfo<Bill> loadAllBill (@Nullable Bill bill, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("createTime desc");
        System.out.println("=======================bill:" +bill + "=======================");
        List<Bill> bills = billDao.getBillWithTypeName(bill);
        bills.forEach(System.out::println);
        return new PageInfo<>(bills);
    }

    public int updateBillById(Bill bill) {
        System.out.println("=======================bill:" +bill + "=======================");
        int update = billDao.updateById(bill);
        return update;
    }

    public Bill getBillById(Integer billId) {
        Bill bill = billDao.selectById(billId);
        return bill;
    }

    public int addNewBill(Bill bill) {
        int insert = billDao.insert(bill);
        return insert;
    }

    public int deleteBillById(Integer billId) {
        int i = billDao.deleteById(billId);
        return i;
    }
}
